  
#include "llvm/Pass.h"
#include "llvm/IR/Function.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
using namespace llvm;
// https://github.com/sampsyo/llvm-pass-skeleton

#define DEBUG_TYPE "mypass"

namespace {
  struct ModuleDependency : public ModulePass {
      static char ID;
      ModuleDependency() : ModulePass(ID) {}

      bool runOnModule(Module &M) override {
        errs() << "Find module " << "!\n";
        return false;
      }
  };

  struct SkeletonPass : public FunctionPass {
    static char ID;
    SkeletonPass() : FunctionPass(ID) {

    }

    virtual bool runOnFunction(Function &F) {
      errs() << "I saw a function called " << F.getName() << "!\n";
      return false;
    }

    void getAnalysisUsage(AnalysisUsage &AU) const {
        AU.setPreservesAll();
        AU.addRequired<ModuleDependency>();
    }
  };
}

char SkeletonPass::ID = 0;
char ModuleDependency::ID = 0;

// Automatically enable the pass.
// http://adriansampson.net/blog/clangpass.html
// static void registerSkeletonPass(const PassManagerBuilder &,
//                          legacy::PassManagerBase &PM) {
//   PM.add(new SkeletonPass());
// }
// static RegisterStandardPasses
//   RegisterMyPass(PassManagerBuilder::EP_EarlyAsPossible,
//                  registerSkeletonPass);
static RegisterPass<ModuleDependency> Y("-", "Example LLVM pass printing each function it visits");
static RegisterPass<SkeletonPass> X("mypass", "Example LLVM pass printing each function it visits");

/*
namespace llvm {
  void initializeSkeletonPassPass(llvm::PassRegistry&);
}

INITIALIZE_PASS_BEGIN(SkeletonPass, DEBUG_TYPE, "Test load pass.", false, false)
//INITIALIZE_PASS_DEPENDENCY(MachineLoopInfo)
//INITIALIZE_PASS_DEPENDENCY(MachineTraceMetrics)
INITIALIZE_PASS_END(SkeletonPass, DEBUG_TYPE, "Test load pass.", false, false)
*/

// namespace llvm {
//   void initializeSkeletonPassPass(llvm::PassRegistry&);
// }
// INITIALIZE_PASS(SkeletonPass, DEBUG_TYPE, "Test load pass.", false, false)